package view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import controller.ClientControler;

public class LikeMessageView {
	
	private ClientControler controlleur;
	
	private javax.swing.JDialog dialog;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton jButtonSoumettreLikeMessage;
    private javax.swing.JLabel jLabelIdMessage;
    private javax.swing.JLabel jLabelTitreLikeMessage;
    private javax.swing.JRadioButton jRadioButtonAime;
    private javax.swing.JRadioButton jRadioButtonAimePas;
    private javax.swing.JTextField jTextFieldIdMessage;
	
	public LikeMessageView(java.awt.Frame parent, boolean modal, ClientControler controlleur) {
		this.controlleur = controlleur;
		initComponents();
	}
	
	public void show() {
		dialog.setVisible(true);
	}
	
	public void close() {
		dialog.setVisible(false);
	}
	
    private void initComponents() {

    	dialog = new javax.swing.JDialog();
        buttonGroup1 = new javax.swing.ButtonGroup();
        jLabelIdMessage = new javax.swing.JLabel();
        jLabelTitreLikeMessage = new javax.swing.JLabel();
        jTextFieldIdMessage = new javax.swing.JTextField();
        jRadioButtonAime = new javax.swing.JRadioButton();
        jRadioButtonAimePas = new javax.swing.JRadioButton();
        jButtonSoumettreLikeMessage = new javax.swing.JButton();

        dialog.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabelIdMessage.setText("Quel est le id du message :");

        jLabelTitreLikeMessage.setFont(new java.awt.Font("Dialog", 0, 24)); // NOI18N
        jLabelTitreLikeMessage.setText("Vous voulez apprecier un message?");

        buttonGroup1.add(jRadioButtonAime);
        jRadioButtonAime.setText("J'aime");

        buttonGroup1.add(jRadioButtonAimePas);
        jRadioButtonAimePas.setText("Je n'aime pas");

        jButtonSoumettreLikeMessage.setText("Soumettre");
        jButtonSoumettreLikeMessage.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
            	String selected;
            	if (jRadioButtonAimePas.isSelected())
            		selected = "0";
            	else selected = "1";
                controlleur.likeMessage(jTextFieldIdMessage.getText(), selected);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(dialog.getContentPane());
        dialog.getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabelTitreLikeMessage))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(82, 82, 82)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jRadioButtonAime)
                            .addComponent(jRadioButtonAimePas)))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabelIdMessage)
                        .addGap(18, 18, 18)
                        .addComponent(jTextFieldIdMessage, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(351, Short.MAX_VALUE)
                .addComponent(jButtonSoumettreLikeMessage)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelTitreLikeMessage)
                .addGap(33, 33, 33)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelIdMessage)
                    .addComponent(jTextFieldIdMessage, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(26, 26, 26)
                .addComponent(jRadioButtonAime)
                .addGap(18, 18, 18)
                .addComponent(jRadioButtonAimePas)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 66, Short.MAX_VALUE)
                .addComponent(jButtonSoumettreLikeMessage)
                .addContainerGap())
        );

        dialog.pack();
    }
}
